from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-25 14:31:35.938370
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 25, Jan, 2021
Time: 14:31:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5039
Nobs: 182.000 HQIC: -46.4460
Log likelihood: 2050.81 FPE: 3.55022e-21
AIC: -47.0883 Det(Omega_mle): 2.19375e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.444954 0.143418 3.102 0.002
L1.Burgenland 0.127865 0.075038 1.704 0.088
L1.Kärnten -0.232606 0.061454 -3.785 0.000
L1.Niederösterreich 0.131979 0.173430 0.761 0.447
L1.Oberösterreich 0.206638 0.150565 1.372 0.170
L1.Salzburg 0.191172 0.079402 2.408 0.016
L1.Steiermark 0.100089 0.107165 0.934 0.350
L1.Tirol 0.163519 0.071499 2.287 0.022
L1.Vorarlberg -0.004383 0.067036 -0.065 0.948
L1.Wien -0.115185 0.143956 -0.800 0.424
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.503730 0.182324 2.763 0.006
L1.Burgenland 0.021017 0.095394 0.220 0.826
L1.Kärnten 0.370575 0.078125 4.743 0.000
L1.Niederösterreich 0.106905 0.220476 0.485 0.628
L1.Oberösterreich -0.171790 0.191409 -0.898 0.369
L1.Salzburg 0.188750 0.100942 1.870 0.061
L1.Steiermark 0.251283 0.136236 1.844 0.065
L1.Tirol 0.136427 0.090894 1.501 0.133
L1.Vorarlberg 0.177236 0.085221 2.080 0.038
L1.Wien -0.571568 0.183007 -3.123 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295904 0.064537 4.585 0.000
L1.Burgenland 0.112057 0.033767 3.319 0.001
L1.Kärnten -0.025873 0.027654 -0.936 0.349
L1.Niederösterreich 0.054941 0.078042 0.704 0.481
L1.Oberösterreich 0.289154 0.067753 4.268 0.000
L1.Salzburg 0.007405 0.035730 0.207 0.836
L1.Steiermark -0.022877 0.048223 -0.474 0.635
L1.Tirol 0.094949 0.032174 2.951 0.003
L1.Vorarlberg 0.116454 0.030166 3.860 0.000
L1.Wien 0.083074 0.064779 1.282 0.200
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219376 0.073938 2.967 0.003
L1.Burgenland -0.010913 0.038685 -0.282 0.778
L1.Kärnten 0.020365 0.031682 0.643 0.520
L1.Niederösterreich 0.019385 0.089410 0.217 0.828
L1.Oberösterreich 0.394019 0.077623 5.076 0.000
L1.Salzburg 0.099529 0.040935 2.431 0.015
L1.Steiermark 0.180786 0.055248 3.272 0.001
L1.Tirol 0.044431 0.036861 1.205 0.228
L1.Vorarlberg 0.093543 0.034560 2.707 0.007
L1.Wien -0.062698 0.074215 -0.845 0.398
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.539890 0.147879 3.651 0.000
L1.Burgenland 0.077821 0.077372 1.006 0.315
L1.Kärnten 0.003258 0.063366 0.051 0.959
L1.Niederösterreich -0.033649 0.178824 -0.188 0.851
L1.Oberösterreich 0.150478 0.155249 0.969 0.332
L1.Salzburg 0.054401 0.081872 0.664 0.506
L1.Steiermark 0.118338 0.110499 1.071 0.284
L1.Tirol 0.217188 0.073723 2.946 0.003
L1.Vorarlberg 0.013100 0.069121 0.190 0.850
L1.Wien -0.127478 0.148434 -0.859 0.390
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153769 0.105092 1.463 0.143
L1.Burgenland -0.018743 0.054986 -0.341 0.733
L1.Kärnten -0.014937 0.045032 -0.332 0.740
L1.Niederösterreich 0.129976 0.127083 1.023 0.306
L1.Oberösterreich 0.396232 0.110329 3.591 0.000
L1.Salzburg -0.023989 0.058183 -0.412 0.680
L1.Steiermark -0.034847 0.078527 -0.444 0.657
L1.Tirol 0.187631 0.052392 3.581 0.000
L1.Vorarlberg 0.047368 0.049122 0.964 0.335
L1.Wien 0.184685 0.105486 1.751 0.080
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220399 0.134121 1.643 0.100
L1.Burgenland 0.083968 0.070174 1.197 0.231
L1.Kärnten -0.047659 0.057470 -0.829 0.407
L1.Niederösterreich -0.016181 0.162186 -0.100 0.921
L1.Oberösterreich -0.104534 0.140804 -0.742 0.458
L1.Salzburg 0.033220 0.074255 0.447 0.655
L1.Steiermark 0.384830 0.100218 3.840 0.000
L1.Tirol 0.494403 0.066864 7.394 0.000
L1.Vorarlberg 0.177311 0.062690 2.828 0.005
L1.Wien -0.224420 0.134624 -1.667 0.096
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128332 0.159019 0.807 0.420
L1.Burgenland 0.015098 0.083201 0.181 0.856
L1.Kärnten -0.108244 0.068139 -1.589 0.112
L1.Niederösterreich 0.224386 0.192295 1.167 0.243
L1.Oberösterreich 0.029502 0.166944 0.177 0.860
L1.Salzburg 0.220907 0.088040 2.509 0.012
L1.Steiermark 0.122037 0.118823 1.027 0.304
L1.Tirol 0.088253 0.079276 1.113 0.266
L1.Vorarlberg 0.024210 0.074328 0.326 0.745
L1.Wien 0.266875 0.159616 1.672 0.095
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.581511 0.085571 6.796 0.000
L1.Burgenland -0.019856 0.044772 -0.444 0.657
L1.Kärnten -0.002262 0.036667 -0.062 0.951
L1.Niederösterreich -0.039379 0.103478 -0.381 0.704
L1.Oberösterreich 0.281922 0.089836 3.138 0.002
L1.Salzburg 0.017224 0.047376 0.364 0.716
L1.Steiermark 0.014205 0.063941 0.222 0.824
L1.Tirol 0.078239 0.042660 1.834 0.067
L1.Vorarlberg 0.150854 0.039997 3.772 0.000
L1.Wien -0.058565 0.085892 -0.682 0.495
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149310 0.003461 0.214408 0.253477 0.067863 0.060585 -0.065871 0.166790
Kärnten 0.149310 1.000000 0.020181 0.198106 0.163222 -0.112701 0.172800 0.025675 0.315740
Niederösterreich 0.003461 0.020181 1.000000 0.302493 0.082818 0.218470 0.138016 0.056333 0.360487
Oberösterreich 0.214408 0.198106 0.302493 1.000000 0.297017 0.306926 0.099773 0.078208 0.129482
Salzburg 0.253477 0.163222 0.082818 0.297017 1.000000 0.158659 0.049032 0.075162 -0.016236
Steiermark 0.067863 -0.112701 0.218470 0.306926 0.158659 1.000000 0.108229 0.091397 -0.099219
Tirol 0.060585 0.172800 0.138016 0.099773 0.049032 0.108229 1.000000 0.160647 0.142903
Vorarlberg -0.065871 0.025675 0.056333 0.078208 0.075162 0.091397 0.160647 1.000000 0.077015
Wien 0.166790 0.315740 0.360487 0.129482 -0.016236 -0.099219 0.142903 0.077015 1.000000